
/**
* 
* ====================================================================
*
* @author apov <apov@ymail.com>
*/ 
// Room.h
//

#pragma once

#include "LobbyEnter.h"
#include "RoomCreate.h"
#include "RoomEnter.h"
#include "RoomExit.h"
#include "RoomToRoom.h"
#include "OperateProcess.h"
#include "AutoMakeRoom.h"
#include "AllUser_RoomExit.h"

class UserManager;
class RoomManager;
class LobbyManager;
class LoginManager;
class NotifyManager;

/**
* @class LobbyService
*  - LobbyService class
*/
class LobbyService{
public:
	enum{
		DEF_MAKE_TYPE_START=		0,
		DEF_MAKE_TYPE_BODY=			1,
		DEF_MAKE_TYPE_END=			2,

		DEF_ROOM_MODE_NORMAL=		0,
		DEF_ROOM_MODE_PREPARE=		1,

		DEF_ROOM_MAX_USER=			10,
		DEF_ROOM_MAX_OBSERVER_USER= 10,
		DEF_LOBBY_MAX_USER=			200,
		DEF_MAX_SEND_BUFFER=		1024,
	};	

	bool initialize( const char* file_name );

	UserManager* getUserManager(){ return users_; }
	RoomManager* getRoomManager(){ return rooms_; }
	LobbyManager* getLobbyManager(){ return channel_; }
	NotifyManager* getNotifyManager(){ return notify_; }

	LobbyEnter* getLobbyEnter(){ return lobby_enter_; }
	RoomCreate* getRoomCreate(){ return room_create_; }
	RoomEnter* getRoomEnter(){ return room_enter_; }
	RoomExit* getRoomExit(){ return room_exit_; }
	RoomToRoom* getRoomToRoom(){ return room_to_room_; }
	AllUser_RoomExit* getAllUserRoomExit(){ return alluser_room_exit_; }
	AutoMakeRoom* getAutoMakeRoom(){ return auto_make_room_; }

	OperateProcess* getOperater(){ return operater_; }

	unsigned int getLobbyUserMax(){ return lobby_max_user_; }
	unsigned int getRoomUserMax(){ return room_max_user_; }
	unsigned int getRoomObserverUserMax(){ return room_max_observer_user_; }
	unsigned int getRoomMax(){ return max_room_; }

	bool isRoomModeNormal(){
		if( room_mode_ == DEF_ROOM_MODE_NORMAL )
			return true;
		return false;
	}

	void setMgrInstance( UserManager* users, RoomManager* rooms, LobbyManager* channel );
	void setActionInstance( LobbyEnter* lobby_enter, RoomCreate* room_create, \
		RoomEnter* room_enter, RoomExit* room_exit, RoomToRoom* roomToRoom = 0 );
	void setUserMax( unsigned int lobby, unsigned int room );	

	int arrange_lobby_instance();

	static LobbyService* Instance();
	static void Shutdown();	

protected:	

private:
	LobbyService();
	virtual ~LobbyService();

	bool loadEnvironment( const char* file_name );

	UserManager* users_;
	RoomManager* rooms_;
	LobbyManager* channel_;	

	LobbyEnter* lobby_enter_;
	RoomCreate* room_create_;
	RoomEnter* room_enter_;
	RoomExit* room_exit_;
	RoomToRoom* room_to_room_;
	AutoMakeRoom* auto_make_room_;
	AllUser_RoomExit* alluser_room_exit_;

	OperateProcess* operater_;
	NotifyManager* notify_;

	unsigned int room_max_user_;	
	unsigned int room_max_observer_user_;
	unsigned int lobby_max_user_;	
	unsigned int max_room_;
	unsigned int room_mode_;	
};

//#pragma data_seg(".Share_lobby_service")
static LobbyService* LobbyService_ = 0;
//#pragma data_seg()
//#pragma comment(linker, "/SECTION:.Share_lobby_service,RWS")
